// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================

package tc.crase.db;

import java.util.Iterator;
import java.util.Vector;

public class Xobject implements Iterable<Xattr> {
	protected int id = -1;
	protected Xdb db = null;
	protected Vector<Xattr> attrs = new Vector<Xattr>();
	
	public int getId() {
		return id;
	}
	
	public void attrAdd(Xattr attr) {
		attrs.add(attr);
	}

	public int attrCount() {
		return attrs.size();
	}
	
	public Xattr attrGet(int index) {
		return attrs.get(index);
	}
	
	public Xdb getDb() {
		return db;
	}
	
	public String getName() {
		String result = "";
		if (db != null) result = getObjectName();
		if (result.isEmpty() == false) return result;
		return "UNDEFINED";
	}
	
	public String getObjectName() {
		return "";
	}
	
	@Override
	public Iterator<Xattr> iterator() {
		return attrs.iterator();
	}
	
	protected Xobject() {
	}
	
	protected void dbOnRemove(Xdb db) {
		db.onRemove(this);
	}
}
